<?php
include("header.php");

// 检查是否传递了 training_id
if (!isset($_GET['id']) || empty($_GET['id'])) {
    die("培训 ID 未指定");
}

$training_id = intval($_GET['id']); // 转换为整数防止 SQL 注入

try {
    $stmt = $pdo->prepare("SELECT * FROM trainings WHERE id = ?");
    $stmt->execute([$training_id]);
    $training = $stmt->fetch(PDO::FETCH_ASSOC);

    if (!$training) {
        die("未找到该培训信息");
    }
} catch (PDOException $e) {
    die("查询失败：" . $e->getMessage());
}
?>


    <style>
        body { font-family: Arial, sans-serif; padding: 20px; }
        h2 { color: #333; }
        dt { font-weight: bold; width: 120px; display: inline-block; }
        dd { margin-left: 0; }
        .field-group { margin-bottom: 15px; }
        .section-title { font-size: 1.2em; margin-top: 20px; border-bottom: 1px solid #ccc; padding-bottom: 5px; }
        .content-section {
            white-space: pre-wrap;
            background-color: #f9f9f9;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        a.button {
            display: inline-block;
            margin-top: 20px;
            padding: 8px 16px;
            background-color: #007BFF;
            color: white;
            text-decoration: none;
            border-radius: 4px;
        }
        a.button:hover {
            background-color: #0056b3;
        }
    </style>

<h2>培训详细信息</h2>
<div class="table-responsive">
    <table class="table table-striped table-hover table-bordered">
        <thead>
            <tr>
                <th>#</th>
                <th>主办科室或学校</th>
                <th>主题</th>
                <th>时间</th>
                <th>培训地点</th>
                <th>任务或自主</th>
            </tr>
        </thead>
        <tbody>
                <tr>
                    <td><?= htmlspecialchars($training['id']) ?></td>
                    <td><?= htmlspecialchars($training['department']) ?></td>
                    <td><?= htmlspecialchars($training['title']) ?></td>
                    <td><?= htmlspecialchars($training['start_time'] . ' 至 ' . $training['end_time']) ?></td>
                    <td><?= htmlspecialchars($training['location']) ?></td>
                    <td><?= htmlspecialchars($training['type']) ?></td>
                </tr>
        </tbody>
    </table>
</div>
<div class="field-group">
    <dt>培训说明：</dt>
    <dd><?= htmlspecialchars($training['content']) ?></dd>
    <dd><?= htmlspecialchars($training['created_at']) ?></dd>
</div>

<?php if (isset($_SESSION['username']) && $_SESSION['username']=='admin'){ ?>
<div class="field-group">
    <a href="training_edit.php?action=edit&id=<?= htmlspecialchars($training['id']) ?>" class="button">修改</a>
    <a href="training_delete.php?id=<?= htmlspecialchars($training['id']) ?>" class="button">删除</a>
</div>
<?php } ?>

<div class="table-responsive">
    <div class="card login-card">
        <div class="card-body">
            <h2 class="card-title text-center mb-4">参加培训教师列表</h2>
            <table class="table table-striped table-hover table-bordered">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>出生年月</th>
                        <th>参加工作时间</th>
                        <th>入职山阳区工作时间</th>
                        <th>任教学科及年级</th>
                        <th>学历及专业</th>
                        <th>职称及取得时间</th>
                        <th>名师骨干层次</th>
                        <th>单位</th>
                        <th>电话</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    // 从数据库中获取教师信息并显示在表格中
                    $stmt = $pdo->query('SELECT * FROM trainings_teachers where training_id = '.$training_id);
                    $idx = 1;
                    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { ?>
                        <tr>
                            <td><?= $idx ?></td>
                            <td><?= $row['teacher_name'] ?></td>
                            <td><?= $row['teacher_sex'] ?></td>
                            <td><?= $row['teacher_birthday'] ?></td>
                            <td><?= $row['teacher_work_time'] ?></td>
                            <td><?= $row['teacher_here_work_time'] ?></td>
                            <td><?= $row['teacher_grade'] . '<br>' . $row['teacher_subject'] ?></td>
                            <td><?= $row['teacher_educational'] . '<br>' . $row['teacher_major'] ?></td>
                            <td><?= $row['teacher_qualifications'] ?></td>
                            <td><?= $row['teacher_master_level'] ?></td>
                            <td><?= $row['teacher_school'] ?></td>
                            <td><?= $row['teacher_phone'] ?></td>
                        </tr>
                    <?php $idx++; } ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php include 'footer.php';?>